package org.example.springboot.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.example.springboot.common.service.impl.BaseServiceImpl;
import org.example.springboot.convert.MoistureControlConvert;
import org.example.springboot.dao.MoistureControlDao;
import org.example.springboot.entity.MoistureControl;
import org.example.springboot.service.MoistureControlService;
import org.example.springboot.vo.MoistureControlVO;
import org.springframework.stereotype.Service;

/**
 * @author Fz
 * @since 1.0.0 2024-07-31
 */
@Service
@AllArgsConstructor
public class MoistureControlServiceImpl extends BaseServiceImpl<MoistureControlDao, MoistureControl> implements MoistureControlService {

    @Override
    public boolean doSaveOrUpdate(JSONObject irrigationTypeMsg, String uuid) {
        MoistureControlVO moistureControlVO = JSON.parseObject(JSON.toJSONString(irrigationTypeMsg), MoistureControlVO.class);
        MoistureControl moistureControl = MoistureControlConvert.INSTANCE.convert(moistureControlVO);
        moistureControl.setIrrigationUnitUuid(uuid);
        return this.saveOrUp(moistureControl);
    }

}